﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using System.Data;
using System.Text;
namespace ZLDC.Estate.Quantify
{
    public partial class lp_YesterDay : System.Web.UI.Page
    {
        string time = string.Empty;
        string opentype = string.Empty;
        public string type = string.Empty;
        public string deptid,depttype;
        protected void Page_Load(object sender, EventArgs e)
        {
            #region
            depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(_Utility.GetInfoBySession().m_sDeptID);//获取部门类型
           
            onload_page();
            #endregion
        }

        /// <summary>
        /// 区经进来选择分行
        /// </summary>
        /// <param name="deptid"></param>
        protected void GetSBranch(string deptid)
        {

            string sql = "select * from t_zlhq_t_s_alldept where  DltFlg=0 and parent_id=" + deptid + "";
                ZLDC.Topo.BLL.Estate.lp_Basis.droplist(sBranch, "name", "id", sql);
               string sldeptid = _Request.GetString("deptid", "0");
               foreach (ListItem item in sBranch.Items)
               {
                   if (item.Value == sldeptid)
                   {
                       item.Selected=true;
                       
                   }
               }
            depttd.Style["display"] = "block";
           
        }
      
        /// <summary>
        /// 加载页面
        /// </summary>
        protected void onload_page()
        {
            type = _Request.GetString("type", "");
            if (type == "")
            {
                deptid = _Utility.GetInfoBySession().m_sDeptID;
            }
            else
            {
                btnUP.Enabled = false;//区经 总监查看
                deptid = _Request.GetString("deptid", "0");
                
            }
            if (!IsPostBack)
            {
               
                time = _Request.GetString("time", "0");
                opentype = _Request.GetString("opentype", "0");
                if (time == "0")
                {
                    txtTime.Text = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
                }
                else
                {
                    txtTime.Text = time;
                }
                if (depttype == "区域")
                {

                    GetSBranch(_Utility.GetInfoBySession().m_sDeptID);
                }
                string GetNumid = GetDeptid();
                 if (GetNumid != "0")
                 {
                     GetList(Convert.ToDateTime(txtTime.Text), type);
                     Getjcts(type);
                     GetNum(Convert.ToDateTime(txtTime.Text));
                     GetCharts(myNext);
                 }
            }
           
        }

        protected void GetBtnList()
        {
            ZLDC.Topo.BLL.Estate.lp_YesterDay.GetBtnList(txtTime,btnUP);
        }


        /// <summary>
        /// 查询未检查工作天数
        /// </summary>
        protected void Getjcts(string type)
        {
            string GetNumid = GetDeptid();
            ZLDC.Topo.BLL.Estate.lp_YesterDay.Getjcts(a1, txtTime, btnUP, opentype, GetNumid);
        }


        /// <summary>
        /// 昨日总分
        /// </summary>
        protected void GetNum(DateTime dt)
        {
            if (_Utility.GetInfoBySession().m_sStation == "分行经理")
            {
                ZLDC.Topo.BLL.Estate.lp_YesterDay.GetNum(dt, Average, YesterDay, CacheUtility.Cache_GetAllChildDept(ZLDC.Topo.BLL.Estate.lp_Basis.getdept1(_Utility.GetInfoBySession().m_sDeptID)), District, deptid,ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(_Utility.GetInfoBySession().m_sDeptID),_Utility.GetInfoBySession().m_sUserID);
            }
            else
            {
                string GetNumid = GetDeptid();
                if(GetNumid!="0")
                ZLDC.Topo.BLL.Estate.lp_YesterDay.GetNum(dt, Average, YesterDay, ZLDC.Topo.BLL.Estate.lp_Basis.getdepttjlist(GetNumid), District, GetNumid, ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(GetNumid), ZLDC.Topo.BLL.Estate.lp_Basis.DeptIDGetUserID(GetNumid));
            }
        }

        /// <summary>
        /// 查询部门人员
        /// </summary>
        protected void GetList(DateTime dt1,string type)
        {
            string GetNumid = GetDeptid();
            ZLDC.Topo.BLL.Estate.lp_YesterDay.GetList(dt1, RpList, btnUP, GetNumid, type);
         
        }

        protected void btnUP_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_YesterDay.BtnUp(RpList, Page, txtTime);
        }

        /// <summary>
        /// 区经进来 取的部门ID
        /// </summary>
        /// <returns></returns>
        protected string GetDeptid()
        {
            return depttype != "区域" ? deptid : (sBranch.Value == "" ? "0" : sBranch.Value);
        }

        protected void btnxx_Click(object sender, EventArgs e)
        {
            
                 GetList(Convert.ToDateTime(txtTime.Text), type);
                 Getjcts(type);
                 GetNum(Convert.ToDateTime(txtTime.Text));
                 GetCharts(myNext);
             
             //Response.Redirect("lp_YesterDay.aspx?deptid=" + GetNumid + "&time="+txtTime.Text+"");

        }

        /// <summary>
        /// 显示饼图
        /// </summary>
        /// <param name="mylist"></param>
        /// <param name="mynext"></param>
        public void GetCharts(Literal mynext)
        {
            string GetNumid = GetDeptid();
            ZLDC.Topo.BLL.Estate.lp_YesterDay.GetCharts(mynext, txtTime, GetNumid, hidchart);
        }

        /// <summary>
        /// 传入用户ID 查询预警
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        protected string YJ(string userid)
        {
            return ZLDC.Topo.BLL.Estate.lp_YesterDay.YJ(userid, txtTime);
        }

      
      
    }
}
